﻿<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Mooville.QUno"
    x:Class="Mooville.QUno.NewGameWindow"
    Title="New Game"
    Width="320" Height="240"
    ResizeMode="NoResize" ShowInTaskbar="False" SnapsToDevicePixels="True" WindowStartupLocation="CenterOwner">
    <Window.Resources>
        <Style x:Key="ValidatingTextBox" TargetType="TextBox">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="True">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid Margin="8">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Label Content="_Your name:" Target="{Binding ElementName=textHuman}" />
        <TextBox 
            Name="textHuman" 
            Text="{Binding Path=HumanPlayerName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" 
            Style="{StaticResource ResourceKey=ValidatingTextBox}"
            Grid.Row="1" />
        <Label Content="_Computer players:" Target="{Binding ElementName=listComputers}" Grid.Row="2" />
        <!-- 
        It would be better if this were a multiple selection list, 
        but I have made it single select to simplify the view model.
        -->
        <ListBox 
            Name="listComputers" 
            ItemsSource="{Binding Path=ComputerPlayers}" 
            IsSynchronizedWithCurrentItem="True"
            SelectionMode="Single"
            Margin="0,0,0,8" 
            Grid.Row="3">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=Name}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <StackPanel Orientation="Horizontal" Margin="0,0,0,8" Grid.Row="4">
            <Button Content="_Add" Width="75" Height="23" Margin="0,0,8,0" Command="local:QUnoCommands.AddPlayer" />
            <Button Content="_Remove" Width="75" Height="23" Command="local:QUnoCommands.RemovePlayer" CommandParameter="{Binding Path=ComputerPlayers.CurrentItem}" />
        </StackPanel>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="5">
            <Button Name="buttonOk" Content="OK" IsDefault="True" Width="75" Height="23" Margin="0,0,8,0" Command="local:QUnoCommands.StartGame" />
            <Button Content="Cancel" IsCancel="True" Width="75" Height="23" />
        </StackPanel>
    </Grid>
</Window>
